﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Evpo.ContactData.Common;

namespace Evpo.ContactData.Data
{
    public class TitleAdapter : AdapterBase, IEditableDictionaryItemAdapter
    {
        public TitleAdapter(Connection conn)
            : base(conn)
        {
            _internalAdapter =  new InternalTitleAdapter(conn);
        }

        #region Properties

        protected override string PrimaryKeyField
        {
            get { return "ID"; }
        }

        protected override string SProcToDelete
        {
            get { return SProcs.DeleteTitle; }
        }

        protected override string SProcToSave
        {
            get { return SProcs.SaveTitle; }
        }

        protected override string SProcToLoad
        {
            get { return SProcs.GetTitle; }
        }

        protected override string SProcToQuery
        {
            get { return SProcs.GetTitles; }
        }
        #endregion Properties

        #region Fields

        private InternalTitleAdapter _internalAdapter;
        #endregion Fields

        #region Methods
        public string GetDisplayName()
        {
            return _internalAdapter.GetDisplayName();
        }

        public DictionaryItem GetItem(int ID)
        {
            return _internalAdapter.GetDictionaryItem<DictionaryItem>(ID);
        }

        public List<DictionaryItem> GetItems()
        {
            return _internalAdapter.GetDictionaryItems<DictionaryItem>(SProcs.GetTitles);
        }

        #endregion Methods
        

        public void Save(DictionaryItem dictItem, bool isNew)
        {
            Save<DictionaryItem>(dictItem, isNew);
        }

        public DictionaryItem CreateNewItem()
        {
            return new DictionaryItem();
        }

        public int GetIDForUnspecified()
        {
            return _internalAdapter.GetIDForUnspecified();
        }

        #region Classes

        private class InternalTitleAdapter : DictionaryItemAdapter
        {
            internal InternalTitleAdapter(Connection _conn):base(_conn){}

            protected override string DictionaryName
            {
                get { return "Title"; }
            }

            protected override string GetItemSProc
            {
                get
                {
                    return SProcs.GetTitle;
                }
            }
        }

        #endregion Classes




    }
}
